$(function() {
    $("#loginBtn").click(function() {
        var username = $("#loginUsername").val();
        var password = $("#loginPassword").val();
        $.post("/api/auth/login", { username: username, password: password }, function(data) {
            localStorage.setItem('token', data.token);
            alert('登录成功');
            window.location.href = 'index.html';
        }).fail(function() {
            alert('登录失败');
        });
    });

    $("#registerBtn").click(function() {
        var username = $("#registerUsername").val();
        var password = $("#registerPassword").val();
        $.post("/api/auth/register", { username: username, password: password }, function(data) {
            alert('注册成功');
        }).fail(function() {
            alert('注册失败');
        });
    });
});
